package com.shinhye.wisdompeking.base;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.shinhye.wisdompeking.MainActivity;
import com.shinhye.wisdompeking.R;

public abstract class BasePager {
	public Context context;
	public View view;
	private SlidingMenu menu;
	private TextView txt_title;
	
	public void setContentView(View view) {
		this.view = view;
	}
	
	public BasePager(Context context) {
		this.context = context;
		menu = ((MainActivity)context).getMenu();
		view = initView();
	}
	
	public View getRootView(){
		return view;
	}
	
	public void initTitleBar() {
		Button btn_left = (Button) view.findViewById(R.id.btn_left);
		btn_left.setVisibility(View.GONE);
		
		ImageButton imgbtn_left = (ImageButton) view.findViewById(R.id.imgbtn_left);
		
		//前景(当前控件显示的内容)
		imgbtn_left.setImageResource(R.drawable.img_menu);
		imgbtn_left.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				menu.toggle();
			}
		});
		
		txt_title = (TextView) view.findViewById(R.id.txt_title);
		
		ImageButton imgbtn_text = (ImageButton) view.findViewById(R.id.imgbtn_text);
		ImageButton imgbtn_right = (ImageButton) view.findViewById(R.id.imgbtn_right);
		ImageButton btn_right = (ImageButton)view.findViewById(R.id.btn_right);
		
		imgbtn_text.setVisibility(View.GONE);
		imgbtn_right.setVisibility(View.GONE);
		btn_right.setVisibility(View.GONE);
	}
	
	/**
	 * 发送网络请求
	 * @param httpMethod
	 * @param url
	 * @param params
	 * @param callBack
	 */
	public void getData(HttpMethod httpMethod, String url,RequestParams params, RequestCallBack<String> callBack) {
		HttpUtils httpUtils = new HttpUtils();
		httpUtils.send(httpMethod, url, params, callBack);
	}
	
	public TextView getTitle() {
		return txt_title;
	}
	
	public SlidingMenu getMenu() {
		return menu;
	}
	
	public MainActivity getActivity() {
		return (MainActivity)context;
	}
	
	public abstract View initView();
	/**
	 * 获取数据
	 */
	public abstract void initData();
}
